import Vue from 'vue';
import VueRouter from 'vue-router';

import {
    getCookie,
    delCookie
} from '@/common/js/cookie.js';

import crypto from '@/common/js/crypto.js';

Vue.use(VueRouter);

const routes = [{
    path: '/',
    component: () => import('../App.vue'),
    redirect: '/overview',
    children: [{
            path: 'login',
            component: () => import('@/views/login.vue'),
        },
        {
            path: 'overview',
            component: () => import('@/views/overview.vue')
        },
        {
            path: 'home',
            component: () => import('@/views/home.vue'),
            redirect: '/home/drgs-analyze',
            children: [
                // {
                //     path: 'overview',
                //     component: () => import('@/views/overview.vue')
                // },
                {
                    path: 'drgs-analyze',
                    component: () => import('@/views/drg/drg-analysis/index.vue'),
                    redirect: '/home/drgs-analyze/hospital-indicator',
                    children: [{
                            path: 'hospital-indicator',
                            component: () => import('../components/drgPage/drgIndexPage.vue')
                        },
                        {
                            path: 'department-contrast',
                            component: () => import('../components/drgPage/deptCompare.vue')
                        },
                        {
                            path: 'MDC-indicator',
                            component: () => import('../components/drgPage/mdcDrgData.vue')
                        },
                        {
                            path: 'department-efficiency',
                            component: () => import('../components/drgPage/deptEfficiency.vue')
                        },
                        {
                            path: 'physician-performance',
                            component: () => import('../components/drgPage/doctorEfficiency.vue')
                        },
                        {
                            path: 'patients-info',
                            component: () => import('../components/drgPage/basicpatientInformation.vue')
                        }
                    ]
                },
                {
                    path: 'no-group',
                    component: () => import('@/views/drg/no-drg'),
                },
                {
                    path: 'doctors-diagnose',
                    component: () => import('@/views/physician-diagnose/index.vue'),
                },
            ]
        },
    ],
}, ];

// history历史模式可以去掉#号
const router = new VueRouter({
    mode: 'history',
    routes,
});
//前置导航守卫   应该放在const创建之前
//前置导航守卫
// import store from '@/store'
// router.beforeEach((to, from, next) => {
//     // to and from are both route objects. must call `next`
//     var isLogin = store.getters['user/isLogin'];
//     if (to.path == '/admin/login' && isLogin) {
//         next();
//     } else if (isLogin) {
//         next();
//     } else if (to.path == '/admin/login') {
//         next();
//     } else {
//         next('/admin/login');
//     }
// })

router.beforeEach((to, from, next) => {
    if (to.path == '/login') {
        next();
    } else if (sessionStorage.getItem('sessionUser')) {
        next();
    } else {
        next('/login');
    }
});

export default router;